package com.gxa.modules.sys.service.impl;

import com.gxa.modules.sys.dto.*;
import com.gxa.modules.sys.entity.OrderSeat;
import com.gxa.modules.sys.entity.Time;
import com.gxa.modules.sys.mapper.OrderSeatMapper;
import com.gxa.modules.sys.service.OrderSeatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public
class OrderSeatServiceImpl implements OrderSeatService {
    @Autowired
    private
    OrderSeatMapper orderSeatMapper;
    @Override
    public
    List<OederSeatDto> queryAll(TimeDto timeDto) {
        List<OederSeatDto> oederSeatDtos = orderSeatMapper.querySeat(timeDto);

        for (int i = 0; i <oederSeatDtos.size() ; i++) {
            Integer seatId = oederSeatDtos.get(i).getSeatId();
            List<OrderSeat> orderSeats = orderSeatMapper.queryOrderSeats(seatId);
            oederSeatDtos.get(i).setOrderSeats(orderSeats);
        }
        return oederSeatDtos;
    }

    @Override
    public void updateState(MyOrderSetDto myOrderSetDto) {
        orderSeatMapper.insertOrder(myOrderSetDto);
        int id = orderSeatMapper.queryIdbyNo(myOrderSetDto.getNo());
        myOrderSetDto.setMyorderId(id);
        for (int i = 0; i < myOrderSetDto.getIds().size(); i++) {
            orderSeatMapper.updateState(myOrderSetDto.getMyorderId(),myOrderSetDto.getIds().get(i));

        }

    }

    @Override
    public
    void updateSeat(UpdateSeatDto updateSeatDto) {
        for (int i = 0; i <updateSeatDto.getBIds().size() ; i++) {
            orderSeatMapper.updateBeforeSeat(updateSeatDto.getBIds().get(i));

        }

        for (int i = 0; i <updateSeatDto.getAIds().size() ; i++) {
            orderSeatMapper.updateAfterSeat(updateSeatDto.getAIds().get(i),updateSeatDto.getMyorderId());

        }

    }

    @Override
    public
    List<TimeDto> queryMd() {
        List<TimeDto> timeDtos = orderSeatMapper.queryMd();
        return timeDtos;
    }

    @Override
    public
    void updateCancel(Integer myorderId) {

        orderSeatMapper.updateCancel(myorderId);
    }

}
